/*
 * Copyright (c) csii.com.cn 2016 zhaojin
 */

package com.csii.ssm.exception;

import com.csii.ssm.util.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zhaojin 15398699939@163.com
 * @create 2016-03-23-下午3:31
 */

public class CoreRuntimeException extends RuntimeException {

    private static final Logger logger;

    static {
        logger = LoggerFactory.getLogger(CoreRuntimeException.class);
    }

    public CoreRuntimeException() {
        super();
    }

    public CoreRuntimeException(String message) {
        super(message);
    }

    public CoreRuntimeException(String message, Throwable cause) {
        super(message, cause);
    }

    public CoreRuntimeException(Throwable cause) {
        super(cause);
    }

    protected CoreRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public static String paserPropertiesMsgForKey(CoreRuntimeException commonRuntimeException) {
        String msgKey = commonRuntimeException.getMessage();
        String msg;
        try {
            msg = SpringContextUtil.getMessage(msgKey);
        }catch (Exception e){
            logger.error("没有找到异常的资源配置信息:{},这里将直接抛出:{}",e,e.getMessage());
            msg = msgKey;
        }
        return msg;
    }

}
